<template>
  <div class="container">
    <a href="javascript:void(0);" @click="listblog">博客</a>
    <div class="list-blog" v-if="showblog">
      <div class="blog-piece" v-for="(blog) in blogs" v-bind:key="blog.id">
        <div class="blog-title">
          #{{ blog.id }} {{ blog.title }}
        </div>
        <div class="blog-write">
          {{ blog.writedate }} {{ blog.writername }}
        </div>
        <div class="blog-content">
          {{ blog.content }}
        </div>
      </div>
    </div>
    <a href="javascript:void(0);" @click="listhenji">痕迹</a>
    <div class="list-henji" v-if="showhenji">
      <div class="henji-piece" v-for="(henji) in henjis" v-bind:key="henji.id">
        <div class="writername">
          {{ henji.writername }}
        </div>
        <div class="writedate">
          {{ henji.writedate }}
        </div>
        <div class="content">
          {{ henji.content }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'homePage',
  mounted () {
    this.$http.post('/java_kunpeng/getall')
      .then((response) => {
        const json = response.data
        if (json.state === '0') {
          this.blogs = json.blogs
          this.henjis = json.henjis
        } else {
          alert('error' + json.msg)
        }
      })
      .catch((error) => {
        alert(error.toString())
      })
  },
  data () {
    return {
      showblog: true,
      showhenji: true,
      blogs: [],
      henjis: []
    }
  },
  methods: {
    listblog: function () {
      this.showblog = !this.showblog
    },
    listhenji: function () {
      this.showhenji = !this.showhenji
    }
  }
}
</script>

<style scoped>
  .blog-piece{
    border:1px black solid;
    margin-top: 10px;
  }
  .blog-title{
    font-size: 18px;
    font-weight: bold;
  }
  .henji-piece{
    border:1px cadetblue solid;
    margin-top: 10px;
  }
  .writername{
    font-weight: bold;
  }
</style>
